package com.xiaomi.eco.dal.query;


public class ApiResultDataRes<T> extends ApiResult {


    private T data;


    public ApiResultDataRes(int code, String message, T data){
        super(code,message);
        this.data=data;
    }

    public ApiResultDataRes(int code, String message){
        super(code,message);
    }


    /**
     * @Description:   成功返回数据
     * @Author: ZSH
     * @Date: 2018/12/25 19:39
     * @param response
     * @return ApiResultDataRes
     */
    public static <T>ApiResultDataRes<T> addSuccess(T response,String message){

        ApiResultDataRes<T> apiResult = new ApiResultDataRes<T>(ApiErrorCode.success.getCode(),message,response);

        return apiResult;
    }

    /**
     * @Description:   成功返回数据
     * @Author: ZSH
     * @Date: 2018/12/25 19:39
     * @param response
     * @return ApiResultDataRes
     */
    public static <T>ApiResultDataRes<T> addSuccess(T response){

        ApiResultDataRes<T> apiResult = new ApiResultDataRes<T>(ApiErrorCode.success.getCode(),ApiErrorCode.success.getMessage(),response);

        return apiResult;
    }

    /**
     * @Description:   成功返回数据
     * @Author: ZSH
     * @Date: 2018/12/25 19:39
     * @param message
     * @return ApiResultDataRes
     */
    public static <T>ApiResultDataRes<T> addSuccessMessage(String message){

        ApiResultDataRes<T> apiResult = new ApiResultDataRes<T>(ApiErrorCode.success.getCode(),message);

        return apiResult;
    }

    /**
     * @Description:  错误信息
     * @Author: ZSH
     * @Date: 2018/12/25 19:47
     * @param apiErrorCode
     * @param message
     * @return ApiResultDataRes<T>
     */
    public static  <T>ApiResultDataRes<T> error(ApiErrorCode apiErrorCode, String message){
        ApiResultDataRes<T> apiResult = new ApiResultDataRes<T>(apiErrorCode.getCode(),message);
        return  apiResult;
    }


    /**
     * @Description:  错误信息
     * @Author: ZSH
     * @Date: 2018/12/28 10:06
     * @param apiErrorCode
     * @param response
     * @return ApiResultDataRes<T>
     */
    public static  <T>ApiResultDataRes<T> error(ApiErrorCode apiErrorCode, T response){
        ApiResultDataRes<T> apiResult = new ApiResultDataRes<T>(apiErrorCode.getCode(),apiErrorCode.getMessage(),response);
        return  apiResult;
    }


    /**
     * @Description:  错误信息
     * @Author: ZSH
     * @Date: 2018/12/25 19:47
     * @param apiErrorCode
     * @return ApiResultDataRes<T>
     */
    public static  <T>ApiResultDataRes<T> error(ApiErrorCode apiErrorCode){
        ApiResultDataRes<T> apiResult = new ApiResultDataRes<T>(apiErrorCode.getCode(),apiErrorCode.getMessage());
        return  apiResult;
    }



    public static  <T>ApiResultDataRes<T> error(String message){
        ApiResultDataRes<T> apiResult = new ApiResultDataRes<T>( ApiErrorCode.server_exception.getCode(),message);
        return  apiResult;
    }



    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
